package com.da.lon.wang.xlg.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.da.lon.wang.xlg.R;
import com.da.lon.wang.xlg.adapter.FilterAdapter;
import com.da.lon.wang.xlg.bean.ResultSearchBean.ResultSearchListBean.SearchResultCategory;
import com.da.lon.wang.xlg.bean.ResultSearchBean.ResultSearchListBean.SearchResultOther;
import com.da.lon.wang.xlg.util.Utils;

import java.util.ArrayList;

public class FilterActivity extends BaseActivity implements OnClickListener {

    private Context context;
    private LinearLayout spaceLayout;
    private ListView filterListView;
    private TextView resetTextView, completeTextView;
    private FilterAdapter adapter;

    private ArrayList<SearchResultOther> otherlist = new ArrayList<SearchResultOther>();
    private ArrayList<SearchResultCategory> categorylist = new ArrayList<SearchResultCategory>();
    private String search_sattr = "";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.ouka_filter);
        context = this;
        spaceLayout = (LinearLayout) findViewById(R.id.ouka_filter_spaceLl);
        spaceLayout.setOnClickListener(this);
        filterListView = (ListView) findViewById(R.id.ouka_filter_lv);

        resetTextView = (TextView) findViewById(R.id.ouka_filter_reset);
        resetTextView.setOnClickListener(this);
        completeTextView = (TextView) findViewById(R.id.ouka_filter_complete);
        completeTextView.setOnClickListener(this);

    }

    @Override
    protected void onStart() {
        super.onStart();
        Intent intent = getIntent();
        otherlist = (ArrayList<SearchResultOther>) intent.getSerializableExtra("otherlist");
        categorylist = (ArrayList<SearchResultCategory>) intent.getSerializableExtra("categorylist");
        search_sattr = intent.getStringExtra("search_sattr");
        getData(otherlist, categorylist);

    }

    private void getData(ArrayList<SearchResultOther> otherlist,
                         ArrayList<SearchResultCategory> categorylist) {

        adapter = new FilterAdapter(context, otherlist, categorylist);
        filterListView.setAdapter(adapter);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.ouka_filter_spaceLl:
                finish();
                overridePendingTransition(R.anim.activity_in_from_left,
                        R.anim.activity_out_to_right);
                break;

            case R.id.ouka_filter_reset:


                Utils.clearFilter(search_sattr);
                adapter.notifyDataSetChanged();


                break;

            case R.id.ouka_filter_complete:
                finish();
                break;

            default:
                break;
        }
    }
}
